package org.tpdata.api.cdss.AssistantDiagnosis;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import common.Data;
import common.RunCaseJson;
import common.SetUpTearDown1;
import exceptions.TestNGRetry;
import io.qameta.allure.Story;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.apache.log4j.Logger;
import org.testng.Assert;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import static common.TestStep.requestAndRespondBody;

public class searchData extends SetUpTearDown1 {

    Logger log = Logger.getLogger(searchData.class);

    @Story("辅助诊疗-临床表现字典相关词语")
    @Parameters({"uri"})
    @Test(retryAnalyzer = TestNGRetry.class,description = "临床表现输入单词，在字典里反馈关联词语")

    public void runCase(String uri) {
        JSONObject json = new JSONObject();
        Data data = envSetUp();
//        Map<String,String > json=new HashMap<String, String>();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("org_ids", "true");
        json.put("domainCode","afw-project" );
        json.put("dataUrl", "/diagPredict/v2/clinicalFeature/list");
        json.put("searchData","咳嗽");
        log.info(json.toString());

        Response response = RunCaseJson.runCase(json, "post", uri);
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);

        JSONObject obj = JSON.parseObject(jsonStr);
        JSONArray contentArr = obj.getJSONArray("responseData");
        String url = RestAssured.baseURI + ":" + RestAssured.port + "/" + uri;
        requestAndRespondBody(url,json,jsonStr);
        Assert.assertNotNull(contentArr.size());  //判断responseData的数据集不为空

    }



}
